package controller;

import entity.Book;
import mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.BookService;

import java.util.List;
@Controller
@ResponseBody
@RequestMapping(produces = "application/json;charset=utf-8")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/getAllBooks")
    public List<Book> getList(){
        List<Book> bookList=bookService.selectAllBooks();
        return bookList;
    }

    @RequestMapping("selectBookById")
    Book selectBookById(int id){
        Book book= bookService.selectBookById(id);
        return book;
    }
    @RequestMapping("deleteBookById")
    String deleteBookById(int id){
        int i=bookService.deleteBookById(id);
        return i> 0 ? "成功":"失败";
    }
    @RequestMapping("insertBook")
    String insertBook(@RequestBody Book book){
        return bookService.insertBook(book)> 0 ? "成功" : "失败";}

    @RequestMapping("updateBool")
    String updateBook(@RequestBody Book book){
            return bookService.updateBook(book)>0?"成功":"失败";
        }

    // 根据书名查询图书
    @RequestMapping("selectBookByBookName")
    List<Book> selectBookByBookName(String bookName) {
        return bookService.selectBookByBookName(bookName);
    }
}



